package org.pageley.games.connected.domain.environment;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.pageley.games.domain.Direction;
import org.pageley.games.domain.Location;
import org.pageley.games.domain.environment.Node;

public abstract class AbstractRoad implements Node {
	private double cost;
	private Set<Direction> directionsFrom;
	private Set<Direction> directionsTo;
	private Location location;

	public AbstractRoad(Location location, double cost,
			Collection<Direction> directionsFrom, Collection<Direction> directionsTo) {
		this.cost = cost;
		this.location = location;
		this.directionsFrom = new HashSet<Direction>(directionsFrom);
		this.directionsTo = new HashSet<Direction>(directionsTo);
	}

	public AbstractRoad(Location location, double cost,
			Collection<Direction> directions) {
		this(location, cost, directions, directions);
	}

	@Override
	public boolean canTravelFrom(Direction outbound) {
		return this.directionsTo.contains(outbound);
	}

	@Override
	public boolean canTravelTo(Direction inbound) {
		return this.directionsFrom.contains(inbound);
	}

	@Override
	public double distanceTo(Node node) {
		return node.getLocation().distanceTo(this.location) + cost - 1.0;
	}

	@Override
	public Location getLocation() {
		return this.location;
	}
	
	
}
